package com.lunar.service.impl;

import com.lunar.entity.Book;
import com.lunar.entity.Discount;
import com.lunar.mapper.BookMapper;
import com.lunar.mapper.DiscountMapper;
import com.lunar.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookMapper bookMapper;

    @Autowired
    private DiscountMapper discountMapper;

    @Override
    public List<Book> getAll() {
        List<Book> books =  bookMapper.selectAll();
        System.out.println(books);
        for (Book book : books) {
            System.out.println(book.getDisid());
            Discount discount = discountMapper.selectByPrimaryKey(book.getDisid());
            System.out.println(discount);
            book.setDiscname(discount.getDiscname());
            book.setDisprice(discount.getDiscvalue() * book.getSaleprice());
        }
        return books;
    }
}
